home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pesquisa Dirigida
/
Pesquisa Dirigida.iso
/
JOGOS
/
parking.swf
/
scripts
/
frame_1
/
DoAction.as
Wrap
Text File
|
2005-01-18
|
16KB
|
583 lines
function Game(timeline, gametype)
{
this.gametype = gametype;
this.timeline = timeline;
this.scores = new Array();
this.finalscore = new Number();
}
function Car()
{
this.rotation = this._rotation;
this.carx = this._x;
this.cary = this._y;
this.delta = 16900;
}
function createGame(gametype)
{
if(_global.game == undefined)
{
_global.game = new Game(this,gametype);
}
else
{
_global.game.gametype = gametype;
}
}
function playButtonClick()
{
this._parent._parent.fadeIntroSound();
_global.player_gender = this._name;
this._parent._parent.createGame(1);
this._parent._parent.gotoAndStop("game1");
}
function startPractice()
{
this.createGame(0);
this.gotoAndStop("game0");
}
function fadeIntroSound()
{
this.onEnterFrame = function()
{
this.audio_mc.intro_sound.setVolume(this.audio_mc.intro_sound.getVolume() - 5);
if(this.audio_mc.intro_sound.getVolume() <= 0)
{
this.audio_mc.intro_sound.stop();
delete this.audio_mc.intro_sound;
delete this.onEnterFrame;
}
};
}
stop();
Game.prototype = new Object();
Game.prototype.startGame = function()
{
var xpos = this.timeline.carplacer._x;
var ypos = this.timeline.carplacer._y;
var depth = this.timeline.carplacer.getDepth();
var rotation = this.timeline.carplacer._rotation;
switch(this.gametype)
{
case 0:
this.timeline.attachMovie("blue_hatchback","car_mc",depth,{_x:xpos,_y:ypos,_rotation:rotation});
this.timeline.car_mc.init(0.6,6,0.4,2,0,20);
break;
case 1:
this.timeline.attachMovie("blue_hatchback","car_mc",depth,{_x:xpos,_y:ypos,_rotation:rotation});
this.timeline.car_mc.init(0.6,6,0.4,2,3,20);
this.timeline.attachMovie("countdownclock","timer_mc",1,{_x:435,_y:5.5});
this.timeline.timer_mc.setChangeHandler("gameOver",this);
this.timeline.timer_mc.setData(0,60,false);
break;
case 2:
this.timeline.attachMovie("black_saloon","car_mc",depth,{_x:xpos,_y:ypos,_rotation:rotation});
this.timeline.car_mc.init(0.7,7,0.34,10,2,20);
this.timeline.timer_mc.reset(false);
break;
case 3:
this.timeline.attachMovie("grey_suv","car_mc",depth,{_x:xpos,_y:ypos,_rotation:rotation});
this.timeline.car_mc.init(0.5,5,0.2,7,0,20);
this.timeline.timer_mc.reset(false);
}
};
Game.prototype.nextGame = function()
{
this.gametype = this.gametype + 1;
this.timeline.gotoAndStop("game" + this.gametype);
};
Game.prototype.gameOver = function()
{
this.timeline.car_mc.stopEngine();
this.calculateScore(0,0,0,true);
};
Game.prototype.retryPractice = function()
{
this.timeline.car_mc.init(0.6,6,0.4,2,0,16);
};
Game.prototype.calculateScore = function(accuracy, hitcar, hitkerb, blnOutOfTime)
{
if(this.gametype > 0)
{
if(this.scores[this.gametype] == undefined)
{
this.scores[this.gametype] = new Object();
}
if(!blnOutOfTime)
{
this.scores[this.gametype].accuracy = accuracy;
this.scores[this.gametype].hitcar = hitcar;
this.scores[this.gametype].hitkerb = hitkerb;
this.scores[this.gametype].timetaken = 60 - this.timeline.timer_mc.getTimeRemaining();
if(accuracy == 0)
{
this.scores[this.gametype].total = 0;
}
else
{
this.scores[this.gametype].total = accuracy - hitcar * 20 - hitkerb * 5 + this.timeline.timer_mc.getTimeRemaining();
}
if(this.scores[this.gametype].total < 0)
{
this.scores[this.gametype].total = 0;
}
this.displayScore(false);
}
else
{
this.scores[this.gametype].accuracy = 0;
this.scores[this.gametype].hitcar = 0;
this.scores[this.gametype].hitkerb = 0;
this.scores[this.gametype].timetaken = 0;
this.scores[this.gametype].total = 0;
if(this.scores[this.gametype].total < 0)
{
this.scores[this.gametype].total = 0;
}
this.displayScore(true);
}
}
else
{
this.timeline.attachMovie("retry practice","retry_mc",15,{_x:352,_y:12});
}
};
Game.prototype.displayScore = function(blnOutOfTime)
{
if(blnOutOfTime)
{
this.timeline.attachMovie("scorepanel","scorepanel_mc",5,{_x:122,_y:10,outoftime:true});
}
else
{
this.timeline.attachMovie("scorepanel","scorepanel_mc",5,{_x:122,_y:10,outoftime:false});
}
};
Game.prototype.getFinalScore = function()
{
var i = 1;
while(i < this.scores.length)
{
this.finalscore += this.scores[i].total;
i++;
}
this.timeline.timer_mc.removeMovieClip();
this.timeline.gotoAndStop("submitscore");
};
Game.prototype.reset = function()
{
this.gametype = undefined;
this.finalscore = 0;
var i = 0;
while(i < 4)
{
this.scores[i].accuracy = 0;
this.scores[i].hitcar = 0;
this.scores[i].hitkerb = 0;
this.scores[i].timetaken = 0;
this.scores[i].total = 0;
i++;
}
_global.seenIntro = true;
this.timeline.gotoAndStop("start");
};
Car.prototype = new MovieClip();
Car.prototype.init = function(acceleration, maxspeed, maxsteering, numcars, numkerbs, numhitpoints)
{
this.accel = acceleration;
this.maxspeed = maxspeed;
this.maxsteering = maxsteering;
this.numparkedcars = numcars;
this.numkerbs = numkerbs;
this.numhitpoints = numhitpoints;
this.maxnegspeed = -4;
this.deccel = 0.4;
this.friction = 0.97;
this.braking = 0.9;
this.maxwheelrotation = 15;
this.ymov = new Number(0);
this.ymov = new Number(0);
this.speed = new Number(0);
this.startangle = this.rotation;
this.wheelrotation = new Number(0);
this.steering = new Number(0);
this.radiance = new Number();
this.point = new Object();
this.oldx = new Number();
this.oldy = new Number();
this.oldrotation = new Number();
this.x1 = new Number();
this.y1 = new Number();
this.x2 = new Number();
this.y2 = new Number();
this.started = false;
this.onkerb = false;
this.hitkerb = new Number(0);
this.hitcar = new Number(0);
this.crashSoundPlaying = false;
this.idleSoundPlaying = false;
this.stopSignShowing = false;
this.stopSignShown = false;
this.attachSounds();
var i = 1;
while(i <= this.numparkedcars)
{
_global.game.timeline["parked" + i]._visible = false;
i++;
}
var i = 1;
while(i <= this.numkerbs)
{
_global.game.timeline["kerb" + i + "_mc"]._visible = false;
i++;
}
_global.game.timeline.target_mc._visible = false;
this._x = this.carx;
this._y = this.cary;
this._rotation = this.rotation;
this.frontwheelleft_mc._rotation = 0;
this.frontwheelright_mc._rotation = 0;
if(this._currentframe > 1)
{
this.gotoAndStop(1);
}
Key.addListener(this);
};
Car.prototype.startEngine = function()
{
this.started = true;
_global.game.timeline.presszstart_mc.play();
this.gotoAndPlay("enginestart");
};
Car.prototype.startMovement = function()
{
this.startIdleSound();
_global.game.timeline.parkingspace_mc._visible = false;
_global.game.timeline.timer_mc.startCountdown();
this.onEnterFrame = this.calculateMove;
};
Car.prototype.stopEngine = function()
{
this.started = false;
_global.game.timeline.timer_mc.stopCountdown();
this.smoke_mc._visible = false;
if(this.stopSignShowing)
{
_global.game.timeline.presszstop_mc.play();
}
this.stopIdleSound();
this.onEnterFrame = undefined;
Key.removeListener(this);
this.checkParking();
};
Car.prototype.checkParking = function()
{
var points = 0;
var targetclip = _global.game.timeline.target_mc;
var minx = targetclip._x;
var maxx = minx + targetclip._width;
var miny = targetclip._y;
var maxy = miny + targetclip._height;
var i = 1;
while(i <= this.numhitpoints)
{
this.point.x = this["hit" + i]._x;
this.point.y = this["hit" + i]._y;
this.localToGlobal(this.point);
if(this.point.x > minx && this.point.x < maxx && this.point.y > miny && this.point.y < maxy)
{
points += 1;
}
i++;
}
var percent = Math.round(points / this.numhitpoints * 100);
_global.game.calculateScore(percent,this.hitcar,this.hitkerb,false);
};
Car.prototype.onKeyUp = function()
{
if(Key.getCode() === 90)
{
if(this.started)
{
this.stopEngine();
}
else
{
this.startEngine();
}
}
};
Car.prototype.renderMove = function()
{
this.xmov = this.speed * Math.sin(this.radiance);
this.ymov = this.speed * Math.cos(this.radiance);
this._x += this.xmov;
this._y -= this.ymov;
this.radiance = this._rotation * 0.017453292519943295;
this.radiance += this.steering * this.speed / 40;
this._rotation = this.radiance * 57.29577951308232;
this.frontwheelleft_mc._rotation = this.wheelrotation;
this.frontwheelright_mc._rotation = this.wheelrotation;
};
Car.prototype.calculateMove = function()
{
this.memox = this._x;
this.memoy = this._y;
this.memorot = this._rotation;
if(Key.isDown(37))
{
this.steering -= 0.05;
this.wheelrotation -= 2.5;
}
if(Key.isDown(39))
{
this.steering += 0.05;
this.wheelrotation += 2.5;
}
if(this.steering > this.maxsteering)
{
this.steering = this.maxsteering;
}
if(this.steering < - this.maxsteering)
{
this.steering = - this.maxsteering;
}
if(this.wheelrotation > this.maxwheelrotation)
{
this.wheelrotation = this.maxwheelrotation;
}
if(this.wheelrotation < - this.maxwheelrotation)
{
this.wheelrotation = - this.maxwheelrotation;
}
if(Key.isDown(38))
{
if(this.speed < this.maxspeed)
{
this.speed += this.accel;
}
}
else if(Key.isDown(40))
{
if(this.speed <= 0)
{
if(this.speed > this.maxnegspeed)
{
this.speed -= this.deccel;
}
}
else
{
this.speed *= this.braking;
}
}
if(this.speed < 0.5 && this.speed > -0.4)
{
this.speed = 0;
}
else
{
this.speed *= this.friction;
}
this.renderMove();
if(this.checkKerbCollision())
{
if(!this.onkerb)
{
this.hitkerb = this.hitkerb + 1;
this.onkerb = true;
}
}
else
{
this.onkerb = false;
}
if(this.checkCarCollisions())
{
if(!this.crashSoundPlaying)
{
this.crash_sound.start();
this.crashSoundPlaying = true;
this.hitcar = this.hitcar + 1;
}
this.undoMove();
this.speed = 0;
}
else if(this.isOutOfBounds())
{
this.undoMove();
this.speed = 0;
}
if(!this.stopSignShown)
{
if(this.carIsInParkingSpace())
{
if(!this.stopSignShowing)
{
_global.game.timeline.presszstop_mc.play();
}
}
else if(this.stopSignShowing)
{
_global.game.timeline.presszstop_mc.play();
}
}
};
Car.prototype.undoMove = function()
{
this._x = this.memox;
this._y = this.memoy;
this._rotation = this.memorot;
};
Car.prototype.isOutOfBounds = function()
{
if(this._x > Stage.width || this._x < 0 || this._y > Stage.height || this._y < 0)
{
return true;
}
return false;
};
Car.prototype.checkKerbCollision = function()
{
if(this.numkerbs > 0)
{
var i = 0;
while(i < this.numkerbs)
{
var num = 10;
var j = 1;
while(j <= num)
{
this.point.x = this["hit" + j]._x;
this.point.y = this["hit" + j]._y;
this.localToGlobal(this.point);
if(_global.game.timeline["kerb" + (i + 1) + "_mc"].hitTest(this.point.x,this.point.y))
{
return true;
}
j++;
}
i++;
}
}
};
Car.prototype.checkCarCollisions = function()
{
var i = 1;
while(i <= this.numparkedcars)
{
var collisionsquare = _global.game.timeline["parked" + i];
if(this.checkObjectWithinRange(collisionsquare))
{
var j = 1;
while(j <= this.numhitpoints)
{
this.point.x = this["hit" + j]._x;
this.point.y = this["hit" + j]._y;
this.localToGlobal(this.point);
var minx = collisionsquare._x - collisionsquare._width / 2;
var maxx = collisionsquare._x + collisionsquare._width / 2;
var miny = collisionsquare._y - collisionsquare._height / 2;
var maxy = collisionsquare._y + collisionsquare._height / 2;
if(this.point.x > minx && this.point.x < maxx && this.point.y > miny && this.point.y < maxy)
{
var car = _global.game.timeline["car" + i + "_mc"];
if(car && car._currentframe == 1)
{
car.gotoAndPlay("alarm");
}
return true;
}
j++;
}
}
i++;
}
return false;
};
Car.prototype.carIsInParkingSpace = function()
{
var parkingspace = _global.game.timeline.target_mc;
if(this.checkObjectWithinRange(parkingspace))
{
var j = 1;
while(j <= this.numhitpoints)
{
this.point.x = this["hit" + j]._x;
this.point.y = this["hit" + j]._y;
this.localToGlobal(this.point);
var minx = parkingspace._x;
var maxx = parkingspace._x + parkingspace._width;
var miny = parkingspace._y;
var maxy = parkingspace._y + parkingspace._height;
if(this.point.x > minx && this.point.x < maxx && this.point.y > miny && this.point.y < maxy)
{
return true;
}
j++;
}
}
return false;
};
Car.prototype.checkObjectWithinRange = function(objtocheck)
{
this.x1 = this._x;
this.y1 = this._y;
this.x2 = objtocheck._x;
this.y2 = objtocheck._y;
var result = (this.x1 - this.x2) * (this.x1 - this.x2) + (this.y1 - this.y2) * (this.y1 - this.y2);
if(result < this.delta)
{
return true;
}
return false;
};
Car.prototype.startIdleSound = function()
{
if(!this.idleSoundPlaying)
{
this.idle_sound.start(0,99);
this.idleSoundPlaying = true;
}
};
Car.prototype.stopIdleSound = function()
{
if(this.idleSoundPlaying)
{
this.idle_sound.stop();
this.idleSoundPlaying = false;
}
};
Car.prototype.attachSounds = function()
{
if(this.crash_sound == undefined)
{
this.crash_sound = new Sound(this);
this.crash_sound.attachSound("crash");
this.crash_sound._parent = this;
this.crash_sound.onSoundComplete = function()
{
this._parent.crashSoundPlaying = false;
};
}
if(this.idle_sound == undefined)
{
this.idle_sound = new Sound(this);
this.idle_sound._parent = this;
this.idle_sound.attachSound("engine_idle");
this.idle_sound.onSoundComplete = function()
{
this._parent.idleSoundPlaying = false;
};
}
};
Object.registerClass("practice_car",Car);
Object.registerClass("blue_hatchback",Car);
Object.registerClass("black_saloon",Car);
Object.registerClass("grey_suv",Car);
_global.serverPath = "http://adverts.freeloader.com/zurich/_scripts/";
_global.prizeDrawScript = "addtoprizedraw.php";
_global.saveScoreScript = "savescore.php";
_global.scoresXML = "scores.xml";
_global.player_gender = new String();
_global.seenIntro = false;